Option Strict Off
Option Explicit On
Friend Class SMSCollectionList
	
	Private mobjList As GenObjArr
	
	'UPGRADE_NOTE: Class_Initialize was upgraded to Class_Initialize_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	Private Sub Class_Initialize_Renamed()
		mobjList = New GenObjArr
	End Sub
	Public Sub New()
		MyBase.New()
		Class_Initialize_Renamed()
	End Sub
	
	Public Sub AddCollection(ByRef CollectionID As String, ByRef CollectionName As String, ByRef OwnedByThisSite As Boolean)
		Dim objColl As SMSCollection
		objColl = New SMSCollection
		objColl.ID = CollectionID
		objColl.Name = CollectionName
		objColl.OwnedByThisSite = OwnedByThisSite
		
		mobjList.Add(objColl)
		
	End Sub
	
	Public Function Count() As Integer
		Count = mobjList.Count
	End Function
	
	Public Function Item(ByRef ZeroBasedIndex As Integer) As SMSCollection
		Item = mobjList.Item(ZeroBasedIndex)
	End Function
	
	Public Function IndexOfCollectionID(ByRef CollectionID As String) As Integer
		IndexOfCollectionID = -1 'default
		Dim lngIndex As Integer
		Dim objColl As SMSCollection
		For lngIndex = 0 To mobjList.Count - 1
			objColl = mobjList.Item(lngIndex)
			If objColl.ID = CollectionID Then
				IndexOfCollectionID = lngIndex
				Exit Function
			End If
		Next lngIndex
	End Function
	
	Public Function NameOfCollectionID(ByRef CollectionID As String) As String
		Dim lngIndex As Integer
		lngIndex = IndexOfCollectionID(CollectionID)
		Dim objColl As SMSCollection
		If lngIndex = -1 Then
			NameOfCollectionID = ""
		Else
			objColl = mobjList.Item(lngIndex)
			NameOfCollectionID = objColl.Name
		End If
	End Function
	
	Public Function IconForCollectionID(ByRef CollectionID As String) As String
		Dim lngIndex As Integer
		lngIndex = IndexOfCollectionID(CollectionID)
		Dim objColl As SMSCollection
		If lngIndex = -1 Then
			IconForCollectionID = "Collection"
		Else
			objColl = mobjList.Item(lngIndex)
			If objColl.OwnedByThisSite = True Then
				IconForCollectionID = "Collection"
			Else
				IconForCollectionID = "CollLock"
			End If
		End If
	End Function
	
	Public Function OwnedByCollectionID(ByRef CollectionID As String) As Boolean
		Dim lngIndex As Integer
		lngIndex = IndexOfCollectionID(CollectionID)
		Dim objColl As SMSCollection
		If lngIndex = -1 Then
			OwnedByCollectionID = True
		Else
			objColl = mobjList.Item(lngIndex)
			If objColl.OwnedByThisSite = True Then
				OwnedByCollectionID = True
			Else
				OwnedByCollectionID = False
			End If
		End If
	End Function
	
	
	Public Function CacheCollections(ByRef SMSProviderConnection As WbemScripting.SWbemServices) As Boolean
		
		On Error GoTo CacheCollectionsErr
		
		Dim objList As WbemScripting.SWbemObjectSet
		Dim objItem As WbemScripting.SWbemObject
		
		mobjList = New GenObjArr
		
		'Set objList = SMSProviderConnection.ExecQuery("Select CollectionID, Name, OwnedByThisSite from SMS_Collection", , wbemFlagForwardOnly)
		objList = SMSProviderConnection.ExecQuery("Select * from SMS_Collection",  , WbemScripting.WbemFlagEnum.wbemFlagForwardOnly)
		
		For	Each objItem In objList
			AddCollection((objItem.Properties_.Item("CollectionID").Value), (objItem.Properties_.Item("Name").Value), CBool(objItem.Properties_.Item("OwnedByThisSite").Value))
		Next objItem
		
		CacheCollections = True
		Exit Function
CacheCollectionsErr: 
		CacheCollections = False
		
	End Function
End Class